<!DOCTYPE html>
<html lang="${LANG}" class="dark">

<head>
    <meta charset="UTF-8">
    <title>QBT_TR(Edit web seed)QBT_TR[CONTEXT=HttpServer]</title>
    <link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
    <script defer src="scripts/localpreferences.js?v=${CACHEID}"></script>
    <script defer src="scripts/color-scheme.js?v=${CACHEID}"></script>
    <script>
        "use strict";

        window.addEventListener("DOMContentLoaded", (event) => {
            window.addEventListener("keydown", (event) => {
                switch (event.key) {
                    case "Enter":
                        event.preventDefault();
                        document.getElementById("editWebSeedButton").click();
                        break;
                    case "Escape":
                        event.preventDefault();
                        window.parent.qBittorrent.Client.closeFrameWindow(window);
                        break;
                }
            });

            const searchParams = new URLSearchParams(window.location.search);
            const origUrl = searchParams.get("url");
            document.getElementById("url").value = decodeURIComponent(origUrl);
            document.getElementById("url").focus();

            document.getElementById("editWebSeedButton").addEventListener("click", (e) => {
                e.stopPropagation();

                fetch("api/v2/torrents/editWebSeed", {
                        method: "POST",
                        body: new URLSearchParams({
                            hash: searchParams.get("hash"),
                            origUrl: origUrl,
                            newUrl: encodeURIComponent(document.getElementById("url").value.trim())
                        })
                    })
                    .then((response) => {
                        if (!response.ok)
                            return;

                        window.parent.qBittorrent.Client.closeFrameWindow(window);
                    });
            });
        });
    </script>
</head>

<body>
    <div style="text-align: center;">
        <br>
        <label for="url">QBT_TR(Web seed URL:)QBT_TR[CONTEXT=PropertiesWidget]</label>
        <div style="text-align: center; padding-top: 10px;">
            <input type="text" id="url" style="width: 90%;">
        </div>
        <br>
        <input type="button" value="QBT_TR(Edit)QBT_TR[CONTEXT=HttpServer]" id="editWebSeedButton">
    </div>
</body>

</html>
